<?php
function addProduct($weida_pdo, $smarty) {
	$product = getParam('o', NULL);
	if ($product) {
		$product = json_decode($product);
		$weida_pdo->exec('INSERT INTO `product` ( id, name, product_type_id, is_active ) VALUES ( null, \'' . $product->name . '\', \'' . $product->product_type_id . '\', \'1\' )');
		$smarty->assign('result', true);
	}
	$smarty->display('xml/xml.tpl');
}

function removeProduct($weida_pdo, $smarty) {
	$product = getParam('o', NULL);
	if ($product) {
		$product = json_decode($product);
		$weida_pdo->exec('DELETE FROM `product` WHERE id = ' . $product->id);
		$smarty->assign('result', true);
	}
	$smarty->display('xml/xml.tpl');
}

function updateProduct($weida_pdo, $smarty) {
	$product = getParam('o', NULL);
	if ($product) {
		$product = json_decode($product);
		$weida_pdo->exec('UPDATE `product` SET name = \'' . $product->name . '\', product_type_id = \'' . $product->product_type_id . '\', is_active = \'' . $product->is_active . '\' WHERE id = ' . $product->id);
		$smarty->assign('result', true);
	}
	$smarty->display('xml/xml.tpl');
}
?>